package pers.dzk.fivelnarow.player.computer;

import pers.dzk.fivelnarow.piece.*;
import pers.dzk.fivelnarow.window.MainWindow;
import java.awt.*;
import java.util.List;
/**
 * @author 丁泽凯
 * 机器人类
 * 使用技术：
 * 1.评估函数
 */
public class AlphaV1 extends ComputerPlayer{
    public AlphaV1(List<Piece> pieces, boolean order) {
        super(pieces, order);
    }
    private Point getPoint(TestPiece[][] tp){
        int maxScore = Integer.MIN_VALUE;
        int x=-1,y=-1;
        for (int i = 0; i < tp.length; i++) {
            for (int j = 0; j < tp.length; j++) {
                TestPiece p = tp[i][j];
                if(p.code == PieceType.空){
                    evaluate.update(j,i,getPieceType());
                    int score = evaluate.getScore(getPieceType());
                    evaluate.update(j,i,PieceType.空);
                    if(maxScore < score){
                        maxScore = score;
                        x=j;
                        y=i;
                    }
                }
            }
        }
        System.out.println(maxScore);
        return new Point(x,y);
    }
    @Override
    public Piece ai() {
        Point index = getPoint(evaluate.select());
        MainWindow.debug.add(index.x+","+index.y);
        for (int i = 0;i < MainWindow.debug.size();i++) {
            System.out.println(i+". "+"("+MainWindow.debug.get(i)+")");
        }
        evaluate.update(index.x,index.y,getPieceType());
        int i = getPieceList().size()-1;
        Piece piece = getPieceList().get(i);
        getPieceList().remove(i);
        piece.setPoint(new Point(MainWindow.getCheckerboard().getPointMatrix()[index.y][index.x]));
        return piece;
    }

}